home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / TIFF_WIN / DO_SCROL.C < prev    next >
Text File  |  1990-04-21  |  24KB  |  530 lines

  1. /*
  2.     this modual contains all the routines to handle the scrolling of a window.
  3.     This routine is called from the "do mouse" modual.
  4. */
  5.  
  6.  
  7. #include "my color.h"
  8. pascal void up_action(ControlHandle, short);
  9. pascal void down_action(ControlHandle, short);
  10. pascal void page_up_action(ControlHandle, short);
  11. pascal void page_down_action(ControlHandle, short);
  12. pascal void thumb_action(void);
  13. RgnHandle    updateRgn = 0L;
  14.  
  15. Boolean    do_controls(the_window, where)    /* the_window is, obviously, the window that is 
  16.                                             active, "where" is the point where the mouse 
  17.                                             was clicked, in global cooridiates, inside 
  18.                                             the active window. do_controls() will return 
  19.                                             TRUE is a control was clicked in otherwise 
  20.                                             it will return FALSE */ 
  21. CWindowPtr    the_window;
  22. Point        where;
  23. {
  24. short            part_code, new_value, which_control, old_value;
  25. short            scroll_amount;
  26. ControlHandle    the_control;
  27. CWindowPtr        owner_window;
  28. Rect            window_rect, draw_rect;
  29. CGrafPtr        the_tiff_picture;
  30. short            which_control_min, which_control_max;
  31.  
  32.  
  33.     if(!updateRgn)
  34.         updateRgn = NewRgn();
  35.     else
  36.         SetEmptyRgn(updateRgn);            /* allow the update region to accumulate into this region */
  37.     
  38.     GlobalToLocal(&where);                /* first convert the mouse location to local coordinates */
  39.     part_code = FindControl(where, the_window, &the_control);    /* now find out what part
  40.                                                                     of the window was clicked in */
  41.     if(!part_code)    return FALSE;        /* if part_code is NULL, then the scroll bars 
  42.                                             were not clicked in */
  43.     switch(part_code)
  44.     {
  45.         case inUpButton:    /* the user clicked in the UP arrow of the scroll bar */
  46.             TrackControl(the_control, where, up_action);
  47.             break;
  48.             
  49.         case inDownButton:    /* the user clicked in the DOWN arrow of the scroll bar */
  50.             TrackControl(the_control, where, down_action);
  51.             break;
  52.         
  53.         case inPageUp:        /* the user is clicking in the page up region of the scroll bar */
  54.             TrackControl(the_control, where, page_up_action);
  55.             break;
  56.             
  57.         case inPageDown:    /* the user is clicking in the page down region of the scroll bar */
  58.             TrackControl(the_control, where, page_down_action);
  59.             break;
  60.         
  61.         case inThumb:        /* the user is draging the "thumb" around */
  62.             old_value = GetCtlValue(the_control);    /* this is the last value the control had before the current activity */
  63.             TrackControl(the_control, where, thumb_action);
  64.             new_value = GetCtlValue(the_control);    /* this is the last value the control had before the current activity */
  65.             owner_window = (CWindowPtr)(**the_control).contrlOwner;    /* I refere to the control's owning window so that I can easily get to the text edit record */
  66.             scroll_amount = new_value - old_value;
  67.             which_control = GetCRefCon(the_control);    /* this is the control that was clicked in */
  68.             which_control_min = GetCtlMin(the_control);
  69.             which_control_max = GetCtlMax(the_control);
  70.             window_rect = owner_window->portRect;
  71.             window_rect.bottom -= BAR_WIDTH;
  72.             window_rect.right -= BAR_WIDTH;
  73.             the_tiff_picture = (CGrafPtr)GetWRefCon(owner_window);
  74.             if(the_tiff_picture)
  75.             {
  76.                 if(which_control == VERTICLE_SCROLL)    /* if we're in the verticle scroll bar move the text down */    
  77.                     {
  78.                         (*the_tiff_picture).portRect.top += scroll_amount;
  79.                         (*the_tiff_picture).portRect.bottom = 
  80.                                                 (*the_tiff_picture).portRect.top + 
  81.                                                 ((*owner_window).portRect.bottom - 
  82.                                                 (*owner_window).portRect.top) - BAR_WIDTH;    
  83.                         if(    (*the_tiff_picture).portRect.bottom > 
  84.                             (**(*the_tiff_picture).portPixMap).bounds.bottom)
  85.                                 (*the_tiff_picture).portRect.bottom = 
  86.                                         (**(*the_tiff_picture).portPixMap).bounds.bottom;        
  87.                         ScrollRect(&window_rect, 0, -scroll_amount, updateRgn); 
  88.                         draw_rect = owner_window->portRect;
  89.                         draw_rect.bottom = draw_rect.top + 
  90.                                         ((*the_tiff_picture).portRect.bottom - 
  91.                                         (*the_tiff_picture).portRect.top);
  92.                         draw_rect.right = draw_rect.left + 
  93.                                         ((*the_tiff_picture).portRect.right - 
  94.                                         (*the_tiff_picture).portRect.left);
  95.                         HLock((*the_tiff_picture).portPixMap);
  96.                         HLock((*owner_window).portPixMap);
  97.                         CopyBits(    *(*the_tiff_picture).portPixMap, 
  98.                                     *(*owner_window).portPixMap, 
  99.                                     &(*the_tiff_picture).portRect, 
  100.                                     &draw_rect, 
  101.                                     srcCopy, 0L);
  102.                         HUnlock((*owner_window).portPixMap);
  103.                         HUnlock((*the_tiff_picture).portPixMap);
  104.                         ValidRgn(updateRgn);
  105.                     }
  106.                 else if (which_control == HORIZONTAL_SCROLL)            /* if we're in the horizontal scroll bar move the text to the left */
  107.                     {
  108.                         (*the_tiff_picture).portRect.left += scroll_amount;            /* allow for the scroll bars when scrolling */
  109.                         (*the_tiff_picture).portRect.right = 
  110.                                                 (*the_tiff_picture).portRect.left + 
  111.                                                 ((*owner_window).portRect.right - 
  112.                                                 (*owner_window).portRect.left) - BAR_WIDTH;    
  113.                         if(    (*the_tiff_picture).portRect.right > 
  114.                             (**(*the_tiff_picture).portPixMap).bounds.right)
  115.                                 (*the_tiff_picture).portRect.right = 
  116.                                     (**(*the_tiff_picture).portPixMap).bounds.right;        
  117.                         ScrollRect(&window_rect, -scroll_amount, 0, updateRgn); 
  118.                         draw_rect = owner_window->portRect;    /* define the destination rectangle for the PixMap */
  119.                         draw_rect.bottom = draw_rect.top + 
  120.                                         ((*the_tiff_picture).portRect.bottom - 
  121.                                         (*the_tiff_picture).portRect.top);
  122.                         draw_rect.right = draw_rect.left + 
  123.                                         ((*the_tiff_picture).portRect.right - 
  124.                                         (*the_tiff_picture).portRect.left);
  125.                         HLock((*the_tiff_picture).portPixMap);
  126.                         HLock((*owner_window).portPixMap);
  127.                         CopyBits(    *(*the_tiff_picture).portPixMap, 
  128.                                     *(*owner_window).portPixMap, 
  129.                                     &(*the_tiff_picture).portRect, 
  130.                                     &draw_rect, 
  131.                                     srcCopy, 0L);
  132.                         HUnlock((*owner_window).portPixMap);
  133.                         HUnlock((*the_tiff_picture).portPixMap);
  134.                         ValidRgn(updateRgn);
  135.                     }
  136.                 }
  137.             break;
  138.     
  139.         default:            /* default to a SysBeep 'cause that will mean something is wrong */
  140.             SysBeep(11);
  141.     }
  142.     return TRUE;    /* TRUE means I successfully handled the controls */
  143. }
  144.  
  145.  
  146. pascal void up_action(control, part)    /* TrackControl will repeatedly call this 
  147.                                             routine as long as the mouse is held down
  148.                                             in the UP arrow of the scroll bar */
  149. ControlHandle    control;
  150. short            part;
  151. {
  152. short    old_control_value, scroll_units, control_min_value, new_control_value;
  153. CWindowPtr    owner_window;
  154. short    which_control;
  155. CGrafPtr    the_tiff_picture;
  156. Rect        window_rect, draw_rect;
  157.  
  158.     scroll_units = 3;        /* this is how many pixels I'll scroll the window */
  159.     which_control = GetCRefCon(control);    /* this is the control that was clicked in */
  160.     old_control_value = GetCtlValue(control);    /* this is the last value the control had before the current activity */
  161.     control_min_value = GetCtlMin(control);        /* this is the minimum value the control can have, this was defined when the control was created */
  162.     new_control_value = old_control_value - scroll_units;    /* this is the new value that the control will have after the scrolling */
  163.     if(new_control_value < control_min_value)    /* if the new control value isn't legitimate */
  164.         SetCtlValue(control, control_min_value);/* just set the control to the minimum value */
  165.     else                                        /* else, set the control value to the new value, the scroll the text */
  166.     {
  167.         SetCtlValue(control, new_control_value);
  168.         owner_window = (CWindowPtr)(**control).contrlOwner;    /* I refere to the control's owning window so that I can easily get to the text edit record */
  169.         window_rect = owner_window->portRect;
  170.         window_rect.bottom -= BAR_WIDTH;
  171.         window_rect.right -= BAR_WIDTH;
  172.         the_tiff_picture = (CGrafPtr)GetWRefCon(owner_window);
  173.         if(the_tiff_picture)
  174.         {
  175.             if(which_control == VERTICLE_SCROLL)    /* if we're in the verticle scroll bar move the text down */    
  176.                 {
  177.                     (*the_tiff_picture).portRect.top -= scroll_units;
  178.                     (*the_tiff_picture).portRect.bottom = (*the_tiff_picture).portRect.top + 
  179.                                                         ((*owner_window).portRect.bottom - 
  180.                                                         (*owner_window).portRect.top) - 
  181.                                                         BAR_WIDTH;    
  182.                     if(    (*the_tiff_picture).portRect.bottom > 
  183.                         (**(*the_tiff_picture).portPixMap).bounds.bottom)
  184.                             (*the_tiff_picture).portRect.bottom = 
  185.                                 (**(*the_tiff_picture).portPixMap).bounds.bottom;        
  186.                     ScrollRect(&window_rect, 0, scroll_units, updateRgn); 
  187.                     draw_rect = owner_window->portRect;    /* define the destination rectangle for the PixMap */
  188.                     draw_rect.bottom = draw_rect.top + 
  189.                                         ((*the_tiff_picture).portRect.bottom - 
  190.                                             (*the_tiff_picture).portRect.top);
  191.                     draw_rect.right = draw_rect.left + 
  192.                                         ((*the_tiff_picture).portRect.right - 
  193.                                             (*the_tiff_picture).portRect.left);
  194.                     HLock((*the_tiff_picture).portPixMap);
  195.                     HLock((*owner_window).portPixMap);
  196.                     CopyBits(    *(*the_tiff_picture).portPixMap, 
  197.                                 *(*owner_window).portPixMap, 
  198.                                 &(*the_tiff_picture).portRect, 
  199.                                 &draw_rect, 
  200.                                 srcCopy, 0L);
  201.                     HUnlock((*owner_window).portPixMap);
  202.                     HUnlock((*the_tiff_picture).portPixMap);
  203.                     ValidRgn(updateRgn);
  204.                 }
  205.             else if (which_control == HORIZONTAL_SCROLL)            /* if we're in the horizontal scroll bar move the text to the left */
  206.                 {
  207.                     (*the_tiff_picture).portRect.left -= scroll_units;/* allow for the scroll bars when scrolling */
  208.                     (*the_tiff_picture).portRect.right = (*the_tiff_picture).portRect.left + 
  209.                                                         ((*owner_window).portRect.right - 
  210.                                                         (*owner_window).portRect.left) - 
  211.                                                         BAR_WIDTH;    
  212.                     if(    (*the_tiff_picture).portRect.right > 
  213.                         (**(*the_tiff_picture).portPixMap).bounds.right)
  214.                             (*the_tiff_picture).portRect.right = 
  215.                                 (**(*the_tiff_picture).portPixMap).bounds.right;        
  216.                     ScrollRect(&window_rect, scroll_units, 0, updateRgn); 
  217.                     draw_rect = owner_window->portRect;    /* define the destination rectangle for the PixMap */
  218.                     draw_rect.bottom = draw_rect.top + 
  219.                                             ((*the_tiff_picture).portRect.bottom - 
  220.                                             (*the_tiff_picture).portRect.top);
  221.                     draw_rect.right = draw_rect.left + 
  222.                                         ((*the_tiff_picture).portRect.right - 
  223.                                         (*the_tiff_picture).portRect.left);
  224.                     HLock((*the_tiff_picture).portPixMap);
  225.                     HLock((*owner_window).portPixMap);
  226.                     CopyBits(    *(*the_tiff_picture).portPixMap, 
  227.                                 *(*owner_window).portPixMap, 
  228.                                 &(*the_tiff_picture).portRect, 
  229.                                 &draw_rect, 
  230.                                 srcCopy, 0L);
  231.                     HUnlock((*owner_window).portPixMap);
  232.                     HUnlock((*the_tiff_picture).portPixMap);
  233.                     ValidRgn(updateRgn);
  234.                 }
  235.             }
  236.     }
  237. }
  238.  
  239. pascal void down_action(control, part)/* TrackControl will call this routine 
  240.                                         repeatedly as long as the mouse is held 
  241.                                         down in the DOWN arrow */
  242. ControlHandle    control;
  243. short            part;
  244. {
  245. short    old_control_value,  scroll_units, control_max_value, new_control_value;
  246. CWindowPtr    owner_window;
  247. short    which_control;
  248. CGrafPtr    the_tiff_picture;
  249. Rect        window_rect, draw_rect;
  250.  
  251.     scroll_units = 3;                            /* this is the number of pixels I'll scroll each time the routine is called */
  252.     which_control = GetCRefCon(control);        /* this is the control the mouse was pressed in */
  253.     old_control_value = GetCtlValue(control);    /* this is the value the controll had when it was last used */
  254.     control_max_value = GetCtlMax(control);        /* this is the maximum value the control can obtain, this was set when the control was defined */
  255.     new_control_value = old_control_value + scroll_units;    /* this is the value the control will be set to when we are done */
  256.     if(new_control_value > control_max_value)    /* if the new control value too large then just set the control to the maximum value */
  257.         SetCtlValue(control, control_max_value);
  258.     else                                        /* else set the controll to the new value and scroll the test */
  259.     {
  260.         SetCtlValue(control, new_control_value);
  261.         owner_window = (CWindowPtr)(**control).contrlOwner;    /* I refere to the control's owning window so that I can easily get to the text edit record */
  262.         window_rect = owner_window->portRect;
  263.         window_rect.bottom -= BAR_WIDTH;
  264.         window_rect.right -= BAR_WIDTH;
  265.         the_tiff_picture = (CGrafPtr)GetWRefCon(owner_window);
  266.         if(the_tiff_picture)
  267.         {
  268.             if(which_control == VERTICLE_SCROLL)    /* if we're in the verticle scroll bar move the text down */    
  269.                 {
  270.                     (*the_tiff_picture).portRect.top += scroll_units;
  271.                     (*the_tiff_picture).portRect.bottom = (*the_tiff_picture).portRect.top + 
  272.                                                             ((*owner_window).portRect.bottom - 
  273.                                                             (*owner_window).portRect.top) - 
  274.                                                             BAR_WIDTH;    
  275.                     if(    (*the_tiff_picture).portRect.bottom > 
  276.                         (**(*the_tiff_picture).portPixMap).bounds.bottom)
  277.                             (*the_tiff_picture).portRect.bottom = 
  278.                                 (**(*the_tiff_picture).portPixMap).bounds.bottom;        
  279.                     ScrollRect(&window_rect, 0, -scroll_units, updateRgn); 
  280.                     draw_rect = owner_window->portRect;    /* define the destination rectangle for the PixMap */
  281.                     draw_rect.bottom = draw_rect.top + 
  282.                                         ((*the_tiff_picture).portRect.bottom - 
  283.                                         (*the_tiff_picture).portRect.top);
  284.                     draw_rect.right = draw_rect.left + 
  285.                                         ((*the_tiff_picture).portRect.right - 
  286.                                         (*the_tiff_picture).portRect.left);
  287.                     HLock((*the_tiff_picture).portPixMap);
  288.                     HLock((*owner_window).portPixMap);
  289.                     CopyBits(    *(*the_tiff_picture).portPixMap, 
  290.                                 *(*owner_window).portPixMap, 
  291.                                 &(*the_tiff_picture).portRect, 
  292.                                 &draw_rect, 
  293.                                 srcCopy, 0L);
  294.                     HUnlock((*owner_window).portPixMap);
  295.                     HUnlock((*the_tiff_picture).portPixMap);
  296.                     ValidRgn(updateRgn);
  297.                 }
  298.             else if (which_control == HORIZONTAL_SCROLL)            /* if we're in the horizontal scroll bar move the text to the left */
  299.                 {
  300.                     (*the_tiff_picture).portRect.left += scroll_units;/* allow for the scroll bars when scrolling */
  301.                     (*the_tiff_picture).portRect.right = (*the_tiff_picture).portRect.left + 
  302.                                                         ((*owner_window).portRect.right - 
  303.                                                         (*owner_window).portRect.left) - 
  304.                                                         BAR_WIDTH;    
  305.                     if(    (*the_tiff_picture).portRect.right > 
  306.                         (**(*the_tiff_picture).portPixMap).bounds.right)
  307.                             (*the_tiff_picture).portRect.right = 
  308.                                 (**(*the_tiff_picture).portPixMap).bounds.right;        
  309.                     ScrollRect(&window_rect, -scroll_units, 0, updateRgn); 
  310.                     draw_rect = owner_window->portRect;    /* define the destination rectangle for the PixMap */
  311.                     draw_rect.bottom = draw_rect.top + 
  312.                                         ((*the_tiff_picture).portRect.bottom - 
  313.                                             (*the_tiff_picture).portRect.top);
  314.                     draw_rect.right = draw_rect.left + 
  315.                                         ((*the_tiff_picture).portRect.right - 
  316.                                             (*the_tiff_picture).portRect.left);
  317.                     HLock((*the_tiff_picture).portPixMap);
  318.                     HLock((*owner_window).portPixMap);
  319.                     CopyBits(    *(*the_tiff_picture).portPixMap, 
  320.                                 *(*owner_window).portPixMap, 
  321.                                 &(*the_tiff_picture).portRect, 
  322.                                 &draw_rect, 
  323.                                 srcCopy, 0L);
  324.                     HUnlock((*owner_window).portPixMap);
  325.                     HUnlock((*the_tiff_picture).portPixMap);
  326.                     ValidRgn(updateRgn);
  327.                 }
  328.             }
  329.     }    
  330. }
  331.  
  332. pascal void page_up_action(control, part)    /* TrackControl will repeatedly call this 
  333.                                                 routine as long as the mouse is held down
  334.                                                 in the PageUp region of the scroll bar */
  335. ControlHandle    control;
  336. short            part;
  337. {
  338. short    old_control_value,  scroll_units, control_min_value, new_control_value;
  339. CWindowPtr    owner_window;
  340. short    which_control;
  341. CGrafPtr    the_tiff_picture;
  342. Rect        window_rect, draw_rect;
  343.  
  344.     scroll_units = 10;                            /* this is the number of pixels I'll scroll each time this routine is called */
  345.     which_control = GetCRefCon(control);
  346.     old_control_value = GetCtlValue(control);    /* this is the value of the scroll bar from the last time it was used */
  347.     control_min_value = GetCtlMin(control);        /* this is the minimum value the scroll bar can obtain, this was set when the scroll bar was defined */
  348.     new_control_value = old_control_value - scroll_units; /* this is the new value for the control */
  349.     if(new_control_value < control_min_value) scroll_units = old_control_value - control_min_value;
  350.     if(old_control_value <= control_min_value)    /* if the new value is too small, just set the control to the minimum value */
  351.         SetCtlValue(control, control_min_value);
  352.     else                                        /* if everything is O.K., set the control to the new value, and scroll the window */
  353.     {
  354.         SetCtlValue(control, old_control_value - scroll_units);
  355.         owner_window = (CWindowPtr)(**control).contrlOwner; /* I refer to the control's owning window so that I can easily get to the text edit record */
  356.         window_rect = owner_window->portRect;
  357.         window_rect.bottom -= BAR_WIDTH;
  358.         window_rect.right -= BAR_WIDTH;
  359.         the_tiff_picture = (CGrafPtr)GetWRefCon(owner_window);
  360.         if(the_tiff_picture)
  361.         {
  362.             if(which_control == VERTICLE_SCROLL)    /* if we're in the verticle scroll bar move the text down */    
  363.                 {
  364.                     (*the_tiff_picture).portRect.top -= scroll_units;
  365.                     (*the_tiff_picture).portRect.bottom = (*the_tiff_picture).portRect.top + 
  366.                                                             ((*owner_window).portRect.bottom - 
  367.                                                             (*owner_window).portRect.top) - 
  368.                                                             BAR_WIDTH;    
  369.                     if(    (*the_tiff_picture).portRect.bottom > 
  370.                         (**(*the_tiff_picture).portPixMap).bounds.bottom)
  371.                             (*the_tiff_picture).portRect.bottom = 
  372.                                 (**(*the_tiff_picture).portPixMap).bounds.bottom;        
  373.                     ScrollRect(&window_rect, 0, scroll_units, updateRgn); 
  374.                     draw_rect = owner_window->portRect;    /* define the destination rectangle for the PixMap */
  375.                     draw_rect.bottom = draw_rect.top + 
  376.                                         ((*the_tiff_picture).portRect.bottom - 
  377.                                             (*the_tiff_picture).portRect.top);
  378.                     draw_rect.right = draw_rect.left + 
  379.                                         ((*the_tiff_picture).portRect.right - 
  380.                                             (*the_tiff_picture).portRect.left);
  381.                     HLock((*the_tiff_picture).portPixMap);
  382.                     HLock((*owner_window).portPixMap);
  383.                     CopyBits(    *(*the_tiff_picture).portPixMap, 
  384.                                 *(*owner_window).portPixMap, 
  385.                                 &(*the_tiff_picture).portRect, 
  386.                                 &draw_rect, 
  387.                                 srcCopy, 0L);
  388.                     HUnlock((*owner_window).portPixMap);
  389.                     HUnlock((*the_tiff_picture).portPixMap);
  390.                     ValidRgn(updateRgn);
  391.                 }
  392.             else if (which_control == HORIZONTAL_SCROLL)            /* if we're in the horizontal scroll bar move the text to the left */
  393.                 {
  394.                     (*the_tiff_picture).portRect.left -= scroll_units;
  395.                     (*the_tiff_picture).portRect.right = (*the_tiff_picture).portRect.left + 
  396.                                                         ((*owner_window).portRect.right - 
  397.                                                         (*owner_window).portRect.left) - 
  398.                                                         BAR_WIDTH;    
  399.                     if(    (*the_tiff_picture).portRect.right > 
  400.                         (**(*the_tiff_picture).portPixMap).bounds.right)
  401.                         (*the_tiff_picture).portRect.right = 
  402.                             (**(*the_tiff_picture).portPixMap).bounds.right;        
  403.                     ScrollRect(&window_rect, scroll_units, 0, updateRgn);
  404.                     draw_rect = owner_window->portRect;    /* define the destination rectangle for the PixMap */
  405.                     draw_rect.bottom = draw_rect.top + 
  406.                                         ((*the_tiff_picture).portRect.bottom - 
  407.                                             (*the_tiff_picture).portRect.top);
  408.                     draw_rect.right = draw_rect.left + 
  409.                                         ((*the_tiff_picture).portRect.right - 
  410.                                             (*the_tiff_picture).portRect.left);
  411.                     HLock((*the_tiff_picture).portPixMap);
  412.                     HLock((*owner_window).portPixMap);
  413.                     CopyBits(    *(*the_tiff_picture).portPixMap, 
  414.                                 *(*owner_window).portPixMap, 
  415.                                 &(*the_tiff_picture).portRect, 
  416.                                 &draw_rect, 
  417.                                 srcCopy, 0L);
  418.                     HUnlock((*owner_window).portPixMap);
  419.                     HUnlock((*the_tiff_picture).portPixMap);
  420.                     ValidRgn(updateRgn);
  421.                 }
  422.             }
  423.     }    
  424. }    
  425.     
  426. pascal void page_down_action(control, part)    /* TrackControl will repeatedly call this 
  427.                                                 routine as long as the mouse is held down
  428.                                                 in the PageDown region of the scroll bar */
  429. ControlHandle    control;
  430. short            part;
  431. {
  432. short    old_control_value,  scroll_units, control_max_value, new_control_value;
  433. CWindowPtr    owner_window;
  434. short    which_control;
  435. CGrafPtr    the_tiff_picture;
  436. Rect        window_rect, draw_rect;
  437.  
  438.     scroll_units = 10;                            /* this is the amount I'll scroll each time this routine is acalled */
  439.     which_control = GetCRefCon(control);        /* this is the ID of scroll bar that was choosen */
  440.     old_control_value = GetCtlValue(control);    /* this is the value of the scroll bar from the last time it was used */
  441.     control_max_value = GetCtlMax(control);        /* this is the maximum value the scroll bar can obtain */
  442.     new_control_value = old_control_value + scroll_units;    /* this is the new value for the scroll bar */
  443.     if(new_control_value > control_max_value) scroll_units = control_max_value - old_control_value;
  444.     if(old_control_value >= control_max_value)    /* if the new value is too large, then just set the control to the maximum value and leave */
  445.         SetCtlValue(control, control_max_value);
  446.     else                                        /* else set the control to the new value, and the  scroll the window */
  447.     {
  448.         SetCtlValue(control, new_control_value);
  449.         owner_window = (CWindowPtr)(**control).contrlOwner;    /* I refere to the control's owning window so that I can easily get to the text edit record */
  450.         window_rect = owner_window->portRect;
  451.         window_rect.bottom -= BAR_WIDTH;/* allow for the scroll bars when scrolling */
  452.         window_rect.right -= BAR_WIDTH;    
  453.         the_tiff_picture = (CGrafPtr)GetWRefCon(owner_window);
  454.         if(the_tiff_picture)
  455.         {
  456.             if(which_control == VERTICLE_SCROLL)    /* if we're in the verticle scroll bar move the text down */    
  457.                 {
  458.                     (*the_tiff_picture).portRect.top += scroll_units;
  459.                     (*the_tiff_picture).portRect.bottom = (*the_tiff_picture).portRect.top + 
  460.                                                             ((*owner_window).portRect.bottom - 
  461.                                                             (*owner_window).portRect.top) - 
  462.                                                             BAR_WIDTH;    
  463.                     if(    (*the_tiff_picture).portRect.bottom > 
  464.                         (**(*the_tiff_picture).portPixMap).bounds.bottom)
  465.                             (*the_tiff_picture).portRect.bottom = 
  466.                                 (**(*the_tiff_picture).portPixMap).bounds.bottom;        
  467.                     ScrollRect(&window_rect, 0, -scroll_units, updateRgn); 
  468.                     draw_rect = owner_window->portRect;    /* define the destination rectangle for the PixMap */
  469.                     draw_rect.bottom = draw_rect.top + 
  470.                                         ((*the_tiff_picture).portRect.bottom - 
  471.                                             (*the_tiff_picture).portRect.top);
  472.                     draw_rect.right = draw_rect.left + 
  473.                                         ((*the_tiff_picture).portRect.right - 
  474.                                             (*the_tiff_picture).portRect.left);
  475.                     HLock((*the_tiff_picture).portPixMap);
  476.                     HLock((*owner_window).portPixMap);
  477.                     CopyBits(    *(*the_tiff_picture).portPixMap, 
  478.                                 *(*owner_window).portPixMap, 
  479.                                 &(*the_tiff_picture).portRect, 
  480.                                 &draw_rect, 
  481.                                 srcCopy, 0L);
  482.                     HUnlock((*owner_window).portPixMap);
  483.                     HUnlock((*the_tiff_picture).portPixMap);
  484.                     ValidRgn(updateRgn);
  485.                 }
  486.             else if (which_control == HORIZONTAL_SCROLL)            /* if we're in the horizontal scroll bar move the text to the left */
  487.                 {
  488.                     (*the_tiff_picture).portRect.left += scroll_units;
  489.                     (*the_tiff_picture).portRect.right = (*the_tiff_picture).portRect.left + 
  490.                                                             ((*owner_window).portRect.right - 
  491.                                                             (*owner_window).portRect.left) - 
  492.                                                             BAR_WIDTH;    
  493.                     if(    (*the_tiff_picture).portRect.right > 
  494.                         (**(*the_tiff_picture).portPixMap).bounds.right)
  495.                             (*the_tiff_picture).portRect.right = 
  496.                                 (**(*the_tiff_picture).portPixMap).bounds.right;        
  497.                     ScrollRect(&window_rect, -scroll_units, 0, updateRgn); 
  498.                     draw_rect = owner_window->portRect;    /* define the destination rectangle for the PixMap */
  499.                     draw_rect.bottom = draw_rect.top + 
  500.                                         ((*the_tiff_picture).portRect.bottom - 
  501.                                             (*the_tiff_picture).portRect.top);
  502.                     draw_rect.right = draw_rect.left + 
  503.                                         ((*the_tiff_picture).portRect.right - 
  504.                                             (*the_tiff_picture).portRect.left);
  505.                     HLock((*the_tiff_picture).portPixMap);
  506.                     HLock((*owner_window).portPixMap);
  507.                     CopyBits(    *(*the_tiff_picture).portPixMap, 
  508.                                 *(*owner_window).portPixMap, 
  509.                                 &(*the_tiff_picture).portRect, 
  510.                                 &draw_rect, 
  511.                                 srcCopy, 0L);
  512.                     HUnlock((*owner_window).portPixMap);
  513.                     HUnlock((*the_tiff_picture).portPixMap);
  514.                     ValidRgn(updateRgn);
  515.                 }
  516.             }
  517.     }
  518. }
  519.  
  520. pascal void thumb_action()        /* I just put this here as an example, I don't have 
  521.                                     anything to do while the user is draging the 
  522.                                     "thumb" around, note that TrackControl does not 
  523.                                     pass any parameters along to this routine, so 
  524.                                     you must allow for global variables if you want 
  525.                                     to do anything "Neat" to the window  */
  526. {
  527.     return;
  528. }
  529.  
  530.